home *** CD-ROM | disk | FTP | other *** search
/ Hunter 2006 / Hunter 2006.iso / soft / sleipnir241.exe / {app} / scripts / ŒŸõ / Grep.js next >
Text File  |  2006-06-15  |  7KB  |  281 lines

  1. var obj, document, id, window;
  2. obj      = new ActiveXObject("Sleipnir.API");
  3. id       = obj.GetDocumentID(obj.ActiveIndex);
  4. document = obj.GetDocumentObject(id);
  5.  
  6. var CurSel;
  7.  
  8. if (document == null) {
  9.     obj.MessageBox('Document é¬èJé⌐éΩé─éóé▄é╣é±');
  10. }else{    
  11.     var query = '('+obj.SearchBarString.replace(/( |ü@)/g,'|')+')';
  12.     var GD = new TGrepData(obj);
  13.     obj.OutputVisible = true;
  14.     obj.OutputClear();
  15.     obj.OutputAddString('Åêù¥Æåé┼é╖...');
  16.     obj.OutputAddString('');
  17.     var progress;
  18.     for (var i= 0; i < obj.GetCount; i++){
  19.         id = obj.GetDocumentID(i);
  20.         GD.AddBookmark(id, query);
  21.         progress = '0% üáüáüáüáüáüáüáüáüáüá 100%';
  22.             for (var j = 0; j < (i + 1) / obj.GetCount * 10; j++){
  23.                 progress = progress.replace('üá', 'üí');
  24.             }
  25.         obj.OutputDeleteString(1);
  26.         obj.OutputAddString(progress);
  27.     }
  28.     GD.OPText.push('âXâNâèâvâgé╠ÅIù╣');
  29.     GD.Output();
  30.     while (true){
  31.         WScript.Sleep(100);
  32.         CurSel = obj.OutputCurSel;
  33.         //âXâNâèâvâgé╠ÅIù╣é≡æIæ≡é╡é─éóé╜éτâïü[âvé⌐éτö▓é»éΘ
  34.         if (CurSel == obj.OutputGetCount() -1){
  35.             obj.OutputClear();
  36.             obj.OutputVisible = false;
  37.             break;
  38.         }
  39.         //Æ╝æOé╔æIæ≡é╡é─éóé╜ìsé╞î╗ì▌æIæ≡é╡é─éóéΘìsé¬ê┘é╚é┴é─éóé╜éτâWâââôâv
  40.         if (GD.CurSelected != CurSel){
  41.             GD.CurSelected = CurSel;
  42.             //IDé╠îƒì⌡
  43.             while (true){
  44.                 if (obj.OutputGetString(CurSel).match(/^\d+/) > 0){
  45.                     id = obj.OutputGetString(CurSel).match(/^\d+/);
  46.                     break;
  47.                 }
  48.                 CurSel--;
  49.             }
  50.             FindTab(id);
  51.             if (GD.Bookmark[GD.CurSelected] != ''){
  52.                 var text = GD.DocumentObject[CurSel].body.createTextRange();
  53.                 text.moveToBookmark(GD.Bookmark[GD.CurSelected]);
  54.                 text.select();
  55.                 text = null;
  56.             }
  57.         }
  58.             
  59.     }
  60.     GD = null;
  61.     document = null;
  62. }
  63. obj = null;
  64. //[MAINEND]
  65.  
  66. /*
  67. TGrepData
  68. Bookmarké╠ĵô╛ôÖé═é╖é╫é─é▒é╠âIâuâWâFâNâgé≡Æ╩é╡é─ìséñ
  69. */
  70. function TGrepData(obj){
  71.     this.obj = obj;
  72.     
  73.     //public method
  74.     this.AddBookmark = AddBookmark;
  75.     this.Output = Output;
  76.     //private method
  77.     this.SetMatchText = SetMatchText;
  78.     this.SetBookmark = SetBookmark;
  79.     this.s = s;    
  80.  
  81.     this.Bookmark = new Array();
  82.     this.DocumentObject = new Array();
  83.     this.OPText = new Array();
  84.     this.CurSelected = 0;
  85.     this.MatchText;
  86. }
  87. /*
  88. AddBookmark(id, query)
  89. id : documentID
  90. query : É│ïKò\î╗
  91. IDé⌐éτDocumentâIâuâWâFâNâgé≡ĵô╛üAÄqâüâ\âbâhé≡ùpéóé─TGrepDataé╠MatchTextüABookmarküAOPTexté≡É▌ÆΦüB
  92. */
  93. function AddBookmark(id, query){
  94.     document = this.obj.GetDocumentObject(id);
  95.     if (document == null){
  96.         return(false);
  97.     }else{
  98.         var aod = new ArrayOfDocument();
  99.         aod.GetDocument(id, null);
  100.     }
  101.     for (var i = 0; i < aod.list.length; i++){
  102.         this.SetMatchText(aod.list[i], query);
  103.         this.SetBookmark(id, aod.list[i], this.MatchText);
  104.     }
  105.     aod = null;
  106.     return(true);
  107. }
  108. /*
  109. Output()
  110. Outputé╔OPTexté≡Åoù═
  111. */
  112. function Output(){
  113.     this.obj.OutputClear();
  114.     for (var i = 0; i < GD.OPText.length; i++){
  115.         this.obj.OutputAddString(this.OPText[i]);
  116.     }
  117.     this.obj.OutputVisible = true;
  118.     this.obj.OutputCurSel = 0;
  119. }
  120.  
  121. /**
  122.  * SetMatchText(document, query)
  123.  * É│ïKò\î╗queryé┼documenté≡îƒì⌡é╡â}âbâ`é╖éΘò╢ÄÜù±é≡ò╘é╖
  124.  * ê°Éö : document documentâIâuâWâFâNâg
  125.  *        query îƒì⌡é╖éΘò╢ÄÜù±üBÉ│ïKò\î╗
  126.  * û▀éΦÆl : â}âbâ`é╖éΘò╢ÄÜù±é≡èiö[é╖éΘözù±üBé╜é╛é╡0ö╘û┌é╠özù±é═ï≤ò╢ÄÜù±
  127.  *
  128. **/
  129. function SetMatchText(document, query){
  130.     var text = document.body.innerText;
  131.     var re = new RegExp(query, 'ig');
  132.     var matchtext = text.match(re);
  133.     var result = new Array();
  134.     var original;
  135.     if (matchtext != null){
  136.         result.push('');
  137.         for (var i = 0; i < matchtext.length; i++){
  138.             original = true;
  139.             //é╖é┼é╔ô»é╢âLü[âÅü[âhé¬ôoÿ^é│éΩé─éóé╜éτæ╜Ådôoÿ^é╡é╚éó
  140.             for (var j = 0; j < result.length; j++){
  141.                 if (matchtext[i].toLowerCase() == result[j].toLowerCase()){
  142.                     original = false;
  143.                     break;
  144.                 }
  145.             }
  146.             if (original){
  147.                 result.push(matchtext[i]);
  148.             }
  149.         }
  150.     }
  151.     
  152.     re = null;
  153.     this.MatchText = result;
  154.     result = null;
  155. }
  156.  
  157. /**
  158.  * SetBookmark(document, query)
  159.  * MatchTexté⌐éτê╩Æué≡î│é╔â\ü[âgé╡é╜TextRangeâIâuâWâFâNâgé╠Bookmark,ïyé╤OPTexté≡É▌ÆΦüB
  160.  * ê°Éö : document documentâIâuâWâFâNâg
  161.           query TGrepData.MatchText
  162.  *
  163. **/
  164.  
  165. function SetBookmark(id, document, query){
  166.     var TempBookmark = new Array();
  167.     var SortData = new Array();
  168.     var TempOPText = new Array();
  169.     var text = document.body.createTextRange();
  170.     var temp = 0;
  171.     for (var i = 1; i < query.length ; i++){
  172.         while (text.findText(query[i])){
  173.             TempBookmark.push(text.getBookmark());
  174.  
  175.             var dup = text.duplicate();
  176.             dup.moveStart('character', -20);
  177.             dup.moveEnd('character', 20);
  178.             TempOPText.push('                 '+dup.text);
  179.             dup = null;
  180.  
  181.             SortData.push(text.offsetTop+':'+temp+':'+text.offsetLeft);
  182.             text.move('character', 1);
  183.             temp++;
  184.         }
  185.         text.move('textedit', -1);
  186.     }
  187.     if (TempBookmark.length != 0){
  188.         this.Bookmark.push('')
  189.         this.OPText.push(id+': ['+document.title+']');
  190.     }
  191.     SortData.sort(this.s);
  192.     //â\ü[âgîïë╩é╔Å]éóBookmarkôÖé≡èiö[é╡é─éóé¡
  193.     for (var j = 0; j < SortData.length ; j++){
  194.             SortData[j].match(/^-?\d+:(.*):-?\d+$/);
  195.             this.Bookmark.push(TempBookmark[RegExp.$1]);
  196.             this.OPText.push(TempOPText[RegExp.$1]);
  197.             if (j == 0){
  198.                 this.DocumentObject[this.OPText.length -2] = document;
  199.             }
  200.     }
  201.     if (TempBookmark.length > 0){
  202.         this.Bookmark.push('')
  203.         this.OPText.push('');
  204.     }
  205.     text = null;
  206.     TempBookmark = null;
  207.     SortData = null;
  208.     TempOPText = null;
  209. }
  210.  
  211. /**
  212.  * s(a, b)
  213.  * SortDataé≡â\ü[âgé╖éΘ
  214.  *
  215. **/
  216. function s(a, b){
  217.     if ((a.match(/^-?\d+/) - b.match(/^-?\d+/)) == 0){
  218.         //Åπé⌐éτé╠ê╩Æué¬êΩÆvé╡é╜éτüAì╢é⌐éτé╠ê╩Æué┼â\ü[âg
  219.         return(a.match(/-?\d+$/) - b.match(/-?\d+$/));
  220.     }
  221.     return(a.match(/^-?\d+/) - b.match(/^-?\d+/));
  222. }
  223. /*
  224.  * FindTab(id)
  225.  * idé⌐éτû┌ôIé╠â^âué≡î⌐é┬é»Åoé╡âAâNâeâBâué╔é╖éΘ
  226.  * ê°Éö : id DocumentID
  227.  *
  228. **/
  229. function FindTab(id){
  230.     var obj;
  231.     obj = new ActiveXObject("Sleipnir.API");
  232.     for (i = 0; i < obj.GetCount; i++){
  233.         if (obj.GetDocumentID(i) == id){
  234.             obj.ActiveIndex = i;
  235.         }
  236.     }
  237.     obj = null;
  238. }
  239. /**
  240.  *ArrayOfDocument
  241.  *âtâîü[âÇâyü[âWé╠é╖é╫é─é╠âhâLâàâüâôâgé≡ò█Ä¥é╖éΘâNâëâX
  242.  *âüâ\âbâh : GetDocument documentâIâuâWâFâNâgé≡ĵô╛é╖éΘ
  243.  *âvâìâpâeâB : list documentâIâuâWâFâNâgé╠özù±
  244.  *
  245. **/
  246. function ArrayOfDocument(){
  247.     var obj = new ActiveXObject("Sleipnir.API");
  248.     this.obj = obj;
  249.     this.GetDocument = GetDocument;
  250.     this.list = new Array();
  251.  
  252. }
  253. /**
  254.  *[ArrayOfDocument]
  255.  *GetDocument(id, document)
  256.  *documentâIâuâWâFâNâgé≡ĵô╛é╡üAlisté╔âZâbâg
  257.  *ê°Éö : id DocumentID
  258.          document documentâIâuâWâFâNâg
  259.  *
  260. **/
  261. function GetDocument(id, document){
  262.     if (document == null){
  263.         document = this.obj.GetDocumentObject(id);
  264.         this.GetDocument(id, document);
  265.     }else if (document.frames.length > 0){
  266.         for (var k = 0; k < document.frames.length; k++) {
  267.             try{
  268.                 var window = document.frames.item(k);
  269.                 this.GetDocument(id, window.document);
  270.             }
  271.             catch(e){
  272.                 break;
  273.             }
  274.         }
  275.     }else{
  276.         this.list.push(document);
  277.     }
  278. }
  279.  
  280. //[END]    
  281.